package apis


import (
	"fmt"
	"net/http"
	"github.com/gin-gonic/gin"
	"github.com/wwalexander/gobencode"
	"app/bt"
	"bytes"
	"io/ioutil"
)

func OnAnnounce(c *gin.Context) ([]byte,error) {

	buf := new(bytes.Buffer)
	request := CreateReqeust(c)

	//response := CreateResponse(c)
	response := bt.Response{}

	bt.OnMethedProcess(&response,request);
	Response(request.InfoHash,&response)

	b, err := bencode.Marshal(response)
	if err != nil {
		fmt.Println("error:", err)
	}
	buf.Write(b)

	return buf.Bytes(),nil
}
func GetAnnounceList(c *gin.Context){

	b,_ := OnAnnounce(c)
	c.String(http.StatusOK,string(b))

}
func GetFileList(c *gin.Context){


	path := "E:\\go\\src\\gotracker\\1.exe"

	_, err := ioutil.ReadFile(path)
	if err != nil{
		fmt.Println(err)
	}
	//fmt.Println(info)
	//result:=string(info)

	c.Header("Connection","Keep-Alive")
	c.Header("Transfer-Encoding","chunked")

	for k,v :=range c.Request.Header {
		fmt.Println(k,v)
	}


	c.JSON(http.StatusOK, gin.H{
		"content":"ok",
	})

}